package com.bf.electroplating.util;

public class CheckPasswordUtils {

    //数字
    public static final String REG_NUMBER = ".*\\d+.*";
    //小写字母
    public static final String REG_UPPERCASE = ".*[A-Z]+.*";
    //大写字母
    public static final String REG_LOWERCASE = ".*[a-z]+.*";
    //特殊符号(~!@#$%^&*()_+|<>,.?/:;'[]{}\)
    public static final String REG_SYMBOL = ".*[~!@#$%^&*()_+|<>,.?/:;'\\[\\]{}\"]+.*";

    public static boolean checkPasswordRule(String password,String username) {
        //密码为空及长度大于8位小于14位判断
        if (password == null || password.length() < 8 || password.length() > 14) {
            return false;
        }
        int i = 0;
        if (password.matches(CheckPasswordUtils.REG_NUMBER)) i++;
        if (password.matches(CheckPasswordUtils.REG_LOWERCASE)) i++;
        if (password.matches(CheckPasswordUtils.REG_UPPERCASE)) i++;
        if (password.matches(CheckPasswordUtils.REG_SYMBOL)) i++;
        //判断密码中是否包含用户名，包含则不满足要求  这里去掉这个判断
        boolean contains = password.contains(username);
        //满足小于三个不符合要求
//        if (i < 3 || contains) return false;
        if (i < 2 ) return false;
        return true;
    }
}
